package com.tools.modules.table.component;

import com.tools.common.utils.Asserts;
import com.tools.modules.table.service.GenFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 生成文件上下文
 * @Author : ShangJY
 * @create 2024/6/2 13:10
 */
@Component
public class GenFileContext {

    @Autowired
    private ApplicationContext applicationContext;

    @Resource
    private Map<String, GenFileService> serviceMap = new HashMap<>();

    @PostConstruct
    private void init(){
        Map<String, GenFileService> beansOfType = applicationContext.getBeansOfType(GenFileService.class);
        serviceMap.putAll(beansOfType);
    }

    public GenFileService select(String type) {
        GenFileService fileService = serviceMap.get(type);
        Asserts.isNull(fileService,"没找到文件的生成类型:"+type);
        return fileService;
    }
}
